package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.BasOrderRule;
import com.wuliu.system.service.IBasOrderRuleService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 单号规则Controller
 *
 * @author realue
 * @date 2023-10-24
 */
@Api(tags = {"运单规则控制器"})
@RestController
@RequestMapping("/system/rule")
public class BasOrderRuleController extends BaseController {
    @Resource
    private IBasOrderRuleService basOrderRuleService;

    /**
     * 查询单号规则列表
     */
    @ApiOperation(value = "查询")
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasOrderRule basOrderRule) {
        basOrderRule.setSysAccount(getSysAccount());
        startPage();
        List<BasOrderRule> list = basOrderRuleService.selectBasOrderRuleList(basOrderRule);
        return getDataTable(list);
    }

    /**
     * 导出单号规则列表
     */
    @ApiOperation(value = "导出")
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "单号规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasOrderRule basOrderRule) {
        basOrderRule.setSysAccount(getSysAccount());
        List<BasOrderRule> list = basOrderRuleService.selectBasOrderRuleList(basOrderRule);
        ExcelUtil<BasOrderRule> util = new ExcelUtil<BasOrderRule>(BasOrderRule.class);
        util.exportExcel(response, list, "单号规则数据");
    }

    /**
     * 获取单号规则详细信息
     */
    @ApiOperation(value = "详情")
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(basOrderRuleService.selectBasOrderRuleById(id));
    }

    /**
     * 新增单号规则
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "单号规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated BasOrderRule basOrderRule) {
        basOrderRule.setSysAccount(getSysAccount());
        basOrderRule.setCreateBy(getUsername());
        return toAjax(basOrderRuleService.insertBasOrderRule(basOrderRule));
    }

    /**
     * 修改单号规则
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "单号规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated BasOrderRule basOrderRule) {
        basOrderRule.setUpdateBy(getUsername());
        return toAjax(basOrderRuleService.updateBasOrderRule(basOrderRule));
    }

    /**
     * 删除单号规则
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "单号规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(basOrderRuleService.deleteBasOrderRuleByIds(ids));
    }
}
